import requests


class IhrnEmpCurd(object):
    # 添加员工
    @classmethod
    def add_emp(cls, header, json):
        url = "http://ihrm-test.itheima.net/api/sys/user"
        resp = requests.post(url=url, headers=header, json=json)
        return resp
    # 查询员工
    @classmethod
    def search_emp(cls, emp_id, header):
        url = "http://ihrm-test.itheima.net/api/sys/user/"+ emp_id
        resp = requests.get(url=url, headers=header)
        return resp
    # 修改员工
    @classmethod
    def modify_emp(cls, emp_id, header, json):
        url = "http://ihrm-test.itheima.net/api/sys/user/" + emp_id
        resp = requests.put(url=url, headers=header, json=json)
        return resp
    # 删除员工
    @classmethod
    def delete_emp(cls, emp_id, header):
        url = "http://ihrm-test.itheima.net/api/sys/user/" + emp_id
        resp = requests.delete(url=url, headers=header)
        return resp


if __name__ == '__main__':
    header ={"Content-Type": "application/json","Authorization":"Bearer 77fa3474-abcd-4dca-be28-293bf15e0146"}
    json = {
        "username": "小猪佩奇",
        "mobile": "13900087655",
        "workNumber": "9527"
    }
    resp = IhrnEmpCurd.add_emp(header, json)
    print(resp.json())

    emp_id = "1528739804550856704"
    resp = IhrnEmpCurd.search_emp(emp_id, header)
    print("查询：", resp.json())

    json =  {
"username":"齐天大圣"
}
    resp = IhrnEmpCurd.modify_emp(emp_id, header, json)
    print("修改：", resp.json())

    resp = IhrnEmpCurd.delete_emp(emp_id, header)
    print("删除：", resp.json())
